<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>公积金查询</title>
    <style type="text/css">
        body{margin:0px; padding:0px;}
        iframe{width:100%;}
    </style>
    <script src=""></script>
    <script src="//r.51gjj.com/common/js/lib/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        var protocolStr = document.location.protocol;
        var app = {
            wsLink:function(){
                try{
                    var ws = {};
                    console.log(protocolStr);
                    switch (protocolStr){
                        case 'http:':
                            ws = new WebSocket("ws://{{{linkUrl}}}");
                            console.log('ws');
                            break;
                        case 'https:':
                            ws = new WebSocket("wss://{{{linkUrl}}}");
                            console.log('wss');
                            break;
                        default:
                            window.alert('系统错误连接失败');
                    }
                }catch (err){
                    window.alert('系统错误连接失败 msg:'+err);
                }
                ws.onopen = function(event){
                    console.log('success link');
                };
                ws.onclose = function(event){
                    console.log('break link');
                }
                ws.onmessage = function(event){
                    console.log(event.data);
                    try{
                        if(event.data.indexOf('redirectUrl') > -1){
                            if(JSON.parse(event.data)){
                                var data = JSON.parse(event.data);

                                returnExecute(data.redirectUrl);

//                                if(data.redirectUrl.indexOf('/') != data.redirectUrl.length-1){
//                                    data.redirectUrl += '/';
//                                }
//                                console.log(data);
//                                var targetIp = "";
//                                for(d in data){
//                                    if(d == 'redirectUrl'){
//                                        continue;
//                                    }
//                                    if(!targetIp){
//                                        targetIp += '?'+d+'='+data[d];
//                                    }else{
//                                        targetIp += '&'+d+'='+data[d];
//                                    }
//                                }
//                                targetIp = data.redirectUrl+targetIp;
//                                if(targetIp.indexOf('http') == -1){
//                                    targetIp = 'http://'+targetIp;
//                                }
//                                window.location.href = targetIp;
                            }
                        }
                    }catch (err){
                        console.error(err);
                    }
                };
            },
            listen:function(){
                if(protocolStr=='https:'){
                    var Mytime = setInterval(function(){
                        params = {
                            orderSn:"{{{orderSn}}}"
                        };
                        $.ajax({ url: "http://{{{listenUrl}}}", type: 'POST', contentType: 'application/json', data:JSON.stringify(params),
                            success: function(response){
                                if(response.errcode==0 && response.data){
                                    if(response.data.redirectUrl){
                                        clearInterval(Mytime);
                                        if(response.data.redirectUrl.indexOf('http')==-1){
                                            response.data.redirectUrl = 'http://'+response.data.redirectUrl;
                                        }
//                                      window.location.href = response.data.redirectUrl;
                                        returnExecute(response.data.redirectUrl);
                                    }
                                }
                            },
                            error: function(error){
                            }
                        });
                    },1000);
                }
            }

        }

        window.onload=function(){ 
            action();
            app.wsLink();
            app.listen();
        }
        window.onresize = function(){
            action();
        }
        function action(){
            var ifm= document.getElementById("myiframe");
            ifm.height=document.documentElement.clientHeight;
        }
        function returnExecute(redirect){
            var ua = window.navigator.userAgent.toLowerCase();//取得浏览器的userAgent字符串
            if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                history.go(-1);
                return;
            }else{
                ("jsInterface" in window)?jsInterface.close():window.close();//关闭窗口
                if(window){
                    history.go(-1);
                    return;
                }
            }
        }
    </script>
</head>
<body>
<iframe src="{{{url}}}" id="myiframe" scrolling="auto" frameborder="0"></iframe>
</body>
</html>